﻿(function () {
    /* Copyright 2010 Imaginary Development. All rights reserved*/
    function DoOnceJquerified() {
        if (typeof ($jq) == 'undefined') {
            if (typeof ($) != 'undefined') {
                $jq = $;
            } else {
                return alert('$jq->jquerify not defined');
            }
        }
        if ($jq('html#facebook').length > 0) {
            alert("Script doesn't work in facebook");
            throw ("Facebook detected");
        }
        if ($jq('div#content.fleet').length != 1) {
            alert('This script is for your starfleet commander fleet screen');
            throw "Not on message screen";
        }
        // fleet explorer main section
        var destination = $jq('div#assign_fleet');
        var shipSelector = $jq('table.fleet');

        var ships = '';
        $jq('td.ship span.image').each(function (index, shipImage) {
            var shipImageName = $jq('img[alt]', shipImage).attr('alt');
            var nameRegexp = new RegExp('([a-zA-z]+)_');
            var name = nameRegexp.exec(shipImageName)[1];

            var quantitySpan = $jq('+ span.quantity', $jq('+ span.name', shipImage))
            if (quantitySpan.length == 0) throw ("Could not locate ship quantity:" + name);
            var quantity = $jq('span[id]',quantitySpan).text()

            ships += name + ' x' + quantity+'<br />';
        });
        $jq(destination).append('<div>' + ships + '</div>');
    };
    var el = document.createElement('div'), b = document.getElementsByTagName('body')[0]; otherlib = false, msg = ''; el.style.position = 'fixed'; el.style.height = '32px'; el.style.width = '220px'; el.style.marginLeft = '-110px'; el.style.top = '0'; el.style.left = '50%'; el.style.padding = '5px 10px 5px 10px'; el.style.zIndex = 1001; el.style.fontSize = '12px'; el.style.color = '#222'; el.style.backgroundColor = '#f99'; if (typeof jQuery != 'undefined') {
        msg = 'This page already using jQuery v' + jQuery.fn.jquery;
        DoOnceJquerified();
        return showMsg();
    } else if (typeof $ == 'function') { otherlib = true; } function getScript(url, success) { var script = document.createElement('script'); script.src = url; var head = document.getElementsByTagName('head')[0], done = false; script.onload = script.onreadystatechange = function () { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { done = true; success(); } }; head.appendChild(script); } getScript('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', function () {
        if (typeof jQuery == 'undefined') { msg = 'Sorry, but jQuery wasn\'t able to load'; } else {

            msg = 'This page is now jQuerified with v' + jQuery.fn.jquery; if (otherlib) { msg += ' and noConflict(). Use $jq(), not $().'; }
            /* Begin AjaxBookmarklet.js */
            DoOnceJquerified();
            /* End AjaxBookmarklet.js */
        } return showMsg();
    }); function showMsg() { el.innerHTML = msg; b.appendChild(el); window.setTimeout(function () { if (typeof jQuery == 'undefined') { b.removeChild(el); } else { jQuery(el).fadeOut('slow', function () { jQuery(this).remove(); }); if (otherlib) { $jq = jQuery.noConflict(); } } }, 2500); }
})();

